package payPakage.wxH5Play;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.alipay.sdk.app.H5PayCallback;
import com.alipay.sdk.app.PayTask;
import com.alipay.sdk.util.H5PayResultModel;

import java.util.HashMap;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

public class WXH5PayPlugin implements MethodChannel.MethodCallHandler {
    public static final String CHANNEL = "com.ahj/WechatH5PayPlugin";
    static MethodChannel channe;
    private Activity activity;

    public static MethodChannel.Result result;

    public WXH5PayPlugin(Activity activity) {
        this.activity = activity;
    }

    public static void registerWith(FlutterEngine flutterEngine, Activity activity12) {
        channe = new MethodChannel(flutterEngine.getDartExecutor(), CHANNEL);
        WXH5PayPlugin plugin = new WXH5PayPlugin(activity12);
        channe.setMethodCallHandler(plugin);
    }


    @Override
    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        try {
            if (methodCall.method.equals("WechatH5Pay")) {
                String payUrl = methodCall.argument("mwebUrl");

                this.result=result;

                Intent intent=new Intent(activity, WXH5PlayActivity.class);
                intent.putExtra("payUrl",payUrl);
                activity.startActivity(intent);

            }

        } catch (Exception e) {
            e.printStackTrace();
            result.success("");
        }
    }

    /**
     * 支付宝SDK支付
     *
     * @param alipayinfo
     */
    public void startAliPay(String alipayinfo, MethodChannel.Result result1) {
        if (TextUtils.isEmpty(alipayinfo)) {
            return;
        }


    }
}
